package com.xsoft.demo12.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.xsoft.demo12.R;
import com.xsoft.demo12.db.UserDataBaseHelper;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class ForgetPasswordActivity extends AppCompatActivity {
    private static final String VALUE_VERIFY_CODE = "653712";
    private EditText passwordEdt;
    private EditText verifyCodeEdt;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_password);
        passwordEdt = (EditText) findViewById(R.id.password_edt);
        verifyCodeEdt = (EditText) findViewById(R.id.verify_code_edt);
        findViewById(R.id.verify_code_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertDialog.Builder(ForgetPasswordActivity.this)
                        .setTitle("验证码")
                        .setMessage("您的验证码为：" + VALUE_VERIFY_CODE)
                        .show();
            }
        });
        findViewById(R.id.update_psd).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String password = passwordEdt.getText().toString().trim();
                if (TextUtils.isEmpty(password)) {
                    return;
                }
                String verifyCode = verifyCodeEdt.getText().toString().trim();
                if (!TextUtils.equals(verifyCode, VALUE_VERIFY_CODE)) {
                    return;
                }
                new UserDataBaseHelper(ForgetPasswordActivity.this).update(getIntent().getStringExtra("phone"), password);
            }
        });

    }
}
